<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<p id ="p1"></p>
		<input type="button" value="停止" onclick="clearInterval(t)" >
		<input type="button" value="启动" onclick="t = setInterval('showTime()',1000)"/>
		<script type="text/javascript">
			var t;
			function showTime(){
				var d = new Date();
				document.getElementById("p1").innerText = d.toLocaleString();
				
				// t = setTimeout("showTime()",1000);
			}
			
			// showTime();
			
			t = setInterval("showTime()",1000)
			
			document.onkeydown = function(){
				var keycode = event.keyCode;
				if(keycode == 13){
					t = setInterval("showTime()",1000)
				}else if(keycode == 32){
					clearInterval(t)
				}
			}
			
		</script>
	</body>
</html>
